package cn.schoolwow.util.test.module.check.common.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.test.module.check.common.domain.AddAssignJob;
import cn.schoolwow.util.test.module.check.common.domain.AddProject;
import cn.schoolwow.util.test.module.compare.instanceList.domain.AddProjectTimeNode;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SetAddProjectInstanceFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        setAddProject(flowContext);
        setTimeNodeList(flowContext);
        setAddAssignJob(flowContext);
    }

    @Override
    public String name() {
        return "设置添加项目示例";
    }

    private void setAddProject(FlowContext flowContext){
        AddProject addProject = new AddProject();
        addProject.departmentId = 1L;
        addProject.projectTemplateId = 2L;
        addProject.creator = 3L;
        addProject.name = "测试项目名称";

        flowContext.putTemporaryData("addProject", addProject);
    }

    private void setTimeNodeList(FlowContext flowContext){
        AddProject addProject = (AddProject) flowContext.checkData("addProject");

        List<AddProjectTimeNode> addProjectTimeNodeList = new ArrayList<>();
        for(int i=0;i<5;i++){
            AddProjectTimeNode addProjectTimeNode = new AddProjectTimeNode();
            addProjectTimeNode.name = "时间节点"+i;
            addProjectTimeNode.deadline = LocalDate.now().plusDays(i);
            addProjectTimeNodeList.add(addProjectTimeNode);
        }
        addProject.timeNodeList = addProjectTimeNodeList;
    }

    private void setAddAssignJob(FlowContext flowContext){
        AddProject addProject = (AddProject) flowContext.checkData("addProject");

        List<AddAssignJob> addAssignJobList = new ArrayList<>();
        {
            AddAssignJob addAssignJob = new AddAssignJob();
            addAssignJob.userId = 1L;
            addAssignJob.username = "张三";
            addAssignJob.analyzeWorkId = 1L;
            addAssignJob.analyzeWorkName = "分析工作1";
            addAssignJob.analyzeTimeNodeNameList = Arrays.asList("时间节点1", "时间节点2");
            addAssignJobList.add(addAssignJob);
        }
        {
            AddAssignJob addAssignJob = new AddAssignJob();
            addAssignJob.userId = 2L;
            addAssignJob.username = "李四";
            addAssignJob.analyzeWorkId = 2L;
            addAssignJob.analyzeWorkName = "分析工作2";
            addAssignJob.analyzeTimeNodeNameList = Arrays.asList("时间节点3", "时间节点4");
            addAssignJobList.add(addAssignJob);
        }
        addProject.assignJobList = addAssignJobList;
    }
}